package com.luohh.treeroom.controller;


import com.alibaba.fastjson.JSONObject;
import com.luohh.treeroom.dto.BaseResult;
import com.luohh.treeroom.dto.LoginParam;
import com.luohh.treeroom.dto.QQLoginParam;
import com.luohh.treeroom.entity.UserInfo;
import com.luohh.treeroom.service.EmailService;
import com.luohh.treeroom.service.IUserInfoService;
import com.luohh.treeroom.service.impl.EmailServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 罗辉煌
 * @since 2020-02-07
 */
@Api(tags = "UserController", description = "关于用户信息接口")
@RestController
@RequestMapping("/user")
public class UserInfoController {

    @Autowired
    IUserInfoService iUserInfoService;
    @Autowired
    EmailServiceImpl emailService;

    @ApiOperation(value = "手机登录")
    @RequestMapping(value="/phoneLogin", method={RequestMethod.POST})
    public BaseResult <UserInfo> phoneLogin(@RequestBody LoginParam loginParam) throws Exception {
        return iUserInfoService.phoneLogin(loginParam);
    }

//    @ApiOperation((value = "账号登陆")
    @RequestMapping(value="/login", method={RequestMethod.POST})
    public BaseResult<UserInfo> login(@RequestBody LoginParam loginParam) throws Exception{
        return iUserInfoService.login(loginParam);
     }

    @ApiOperation(value = "邮件验证码")
    @RequestMapping(value = "/getCode" ,method = {RequestMethod.POST})
    public BaseResult<UserInfo> getCode(@RequestBody JSONObject email) throws  Exception{
        String to = email.getString("email");
        return iUserInfoService.getCode(to);
    }

    @ApiOperation(value = "获取用户信息")
        @RequestMapping(value = "/getUserInfo",method = {RequestMethod.POST})
    public BaseResult getDetail() throws  Exception {
        return iUserInfoService.getDetail();
    }

    @ApiOperation(value = "登出")
    @RequestMapping(value = "/loginout",method = {RequestMethod.POST})
    public BaseResult loginot(){
        return iUserInfoService.logout();
    }

    @RequestMapping(value = "/qqLogin",method = {RequestMethod.POST})
    public BaseResult qqLogin(@RequestBody QQLoginParam qqLoginPrame) throws  Exception {
        return iUserInfoService.qqLogin(qqLoginPrame);}
}

